<?php
namespace pad;
/*
*报工端-生产报工类
*/

class workReportClass extends indexClass
{
    private const page = 'processReport';
    private const table = 'process_report';
    private const tableMx = 'process_report_detail';
    private const title = '生产报工';
    private const type = 'workReport';

    /*列表-查询条件*/
    /**
     * 生产报工
     */
    public function home()
    {

        if(!isset($_SESSION[self::type]['search_text']))$this->conditions();
        $choiceBlock = $this->choiceBlock(self::type);
        $condition = $_SESSION[self::type]['condition_arr'];
        //全等查询数组
        $equal = array(
            'coid' => self::$coid,
            'classify'=>'生产派工',
            'state'=>'已确认'
        );
        //like查询数组
        $like = array(
        );
        $where = search(array("like" => $like, "=" => $equal));
        //根据查询条件生成sql
        foreach ((array)$condition as $key=>$value){
            switch ($key)
            {
                case "date":
                    foreach ((array)$value as $val){
                        $where .= $this->getTimePeriod($val,'date','startDate');
                    }
                    break;
                case "state":
                    foreach ((array)$value as $val){
                        $where .= match ($val) {
                            '待报工' => " and id not in (select distinct sendId from process_report where coid = '".self::$coid."') ",
                            '部分报工' => " and workFlow = 0 and id in (select distinct sendId from process_report where coid = '".self::$coid."') ",
                            '已报工' => " and workFlow = 1 ",
                            default=>'',
                        };
                    }
                    break;
                case "type":
                    $where .= " and type in ('".implode("','",$value)."') ";
                    break;
                case "product_line":
                    $where .= " and lineId in ('".implode("','",$value)."') ";
                    break;
                default:
                    $where .= "";
            }
        }
        if(isset($_SESSION[self::type]['orderNo'])){
            $where .= " and orderNo like '%".$_SESSION[self::type]['orderNo']."%' ";
        }
        $result = find(array("table" => "machining_send_order", "field" => " * ", "where" => " 1=1 {$where} order by recordDate desc,orderNo desc "));
        $ul = "";
        if(is_array($result['array'])){
            foreach ($result['array'] as $array){
                $line = query('product_line', "id = '$array[lineId]'");
                $team = query('team', "id = '$array[teamId]'");
                $process = query('process', "id = '$array[processId]'");
                $material = query('material', "id = '$array[materialId]'");
                $reportNum = find(array(
                    "table"=>"process_report",
                    "field"=>" ifnull(sum(yield),0) as num ",
                    "single"=>" coid = '".self::$coid."' and classify = '工序报工' and sendId = '".$array['id']."' "
                ))['num']?:0;
                $name = $material['code'].','.
                    $material['name'].','.
                    $material['model'];
                $ul .= "<ul data-id='{$array['id']}' onclick=\"sureChoice('{$array['id']}')\">
                    <li>{$array['orderNo']}</li>
                    <li>{$name}</li>
                    <li>".$line['workshop'] . '-' . $line['name']."</li>
                    <li>{$process['name']}</li>
                    <li>".($team['name']?:'无')."</li>
                    <li>".self::lostZero($array['num'],'numPrecision')."</li>
                    <li>".self::lostZero($reportNum,'numPrecision')."</li>
                    <li>{$array['startDate']}</li>
                </ul>";
            }
        }
        $orderNo = isset($_SESSION[self::type]['orderNo'])?$_SESSION[self::type]['orderNo']:'';
        //生成页面
        $html = $this->commonHead('生产报工')."
		<div class='center'>
           <div class='search'>
                <div class='flex-div'>
                    <p class='search-left'>
                       <span class='search-title'>报工单</span>
                       <span style='position: relative'>
                            <input type='text' name='orderNo' autocomplete='off' id='orderCode' placeholder='输入' title='输入' class='text'  value='".$orderNo."' onblur=\"searchFormRender('workReport')\">
                            <!--<img onclick=\"layer('moveStock','choiceLocation')\" class='search-scan' src='".root."img/control/scan.svg'>-->
                        </span>
                        
                    </p>
                    <p>
                        <span>筛选条件：</span>
                        <span>".$_SESSION[self::type]['search_text']."</span>
                    </p>
                </div>
                <div class='search-right'><img onclick=\"animatedOperation('choice-block','right','show')\" src='".root."img/control/detail.svg' alt=''></div>
            </div>
           <div class='content'>
                <ul>
                    <li>派工单号</li>
                    <li>产品信息</li>
                    <li>生产线</li>
                    <li>工序</li>
                    <li>班组</li>
                    <li>计划数量</li>
                    <li>报工数量</li>
                    <li>开始时间</li>
                </ul>
                {$ul}
            </div>
		</div>
		<div class='footer'>
           <p>
                <input type='hidden' name='choiceId' value=''>
                <button type='button' class='newButton' onClick=\"workReport()\">报工</button>
            </p>
		</div>
        ".$this->commonNavigation('生产报工').$choiceBlock;
        $js   = "
        <script>
        function sureChoice(id){
            $(\"[name='choiceId']\").val(id)
        }
        function workReport(){
            var id = $(\"[name='choiceId']\").val()
            if (!id){
                 msg('请先选择派工单，再进行报工','error');
            }else{
                window.location.href = root+'pad/index.html?cla=workReport&fun=workReportDetail&orderMxId='+id;
            }
        }
        $(function(){
            
        })
        </script>".$this->jsReport();
        return head("report") . $html . $js . warn() . "\n</body>\n</html>";
    }

    /**
     * 报工详情
     */
    public function workReportDetail()
    {
        $id = $this->get('id')?:'';
        $process_report = query("process_report"," id = '$id' ");
        $orderMxId = $process_report['sendId']?:$this->get('orderMxId');
        $machining_send_order = query("machining_send_order"," id = '$orderMxId' ");
        $line = query('product_line', "id = '$machining_send_order[lineId]'");
        $process = query('process', "id = '$machining_send_order[processId]'");
        $material = query('material', "id = '$machining_send_order[materialId]'");
        $routing_detail = query('routing_detail', "id = '$machining_send_order[routingMxId]'");
        $reportNum = find(array("table"=>"process_report","field"=>" ifnull(sum(yield),0) as num ","single"=>" coid = '".self::$coid."' and classify = '工序报工' and sendId = '".$machining_send_order['id']."' "))['num']?:0;
        $name = $material['code'].','.
            $material['name'].','.
            $material['model'];
        $machining_send_order['text'] = $machining_send_order['text']?:'无';
        $teamId = $process_report['teamId']?:$machining_send_order['teamId'];
        $teamType = explode('，', para('teamType'));
        //数字键盘
        $tr = "<tr>";
        for ($i = 1; $i < 10; $i++) {
            $tr .= "<td class='key-item' data-num='$i' data-name='yield'>$i</td>";
            if($i%3==0){
                $tr .= "</tr><tr>";
            }
        }
        $calculator = "<div class='calculator'>
                            <table class='table-calculator'>
                                $tr
                                <tr>
                                    <td class='key-item' data-num='0' data-name='yield'>0</td>
                                    <td class='key-item spot' data-num='spot' data-name='yield'>.</td>
                                    <td class='key-item delete' data-num='delete' data-name='yield'><img src='".root."img/control/calculator_del.svg' alt=''></td>
                                </tr>
                            </table>
                        </div>";
        //缺陷
        $defectOption = $process['id'] ? explode('，', $process['defectType']) : [];
        $result = find(array('table' => 'process_report_detail', 'where' => " orderId = '$process_report[id]' order by list asc"));
        $clockRuleTr = "";
        if (is_array($result['array']) && count($result['array']) > 0) {
            foreach ($result['array'] as $k => $array) {
                if ($k == 0) {
                    $button = "<span class='op-but' onclick='addRow(this)'>+</span>";
                } else {
                    $button = "<span class='op-but' onclick='decRow(this)'>-</span>";
                }
                $input = hidden(array('name' => 'mxId[]', 'value' => $array['id'])) . select(["name" => "problem[]", "title" => "请选择", "class" => "b-b-input-30", 'option' => $defectOption, 'value' => $array['problem']]) . text(array('name' => 'num[]',"class"=>"text b-b-input-30", 'title' => '数量', 'value' => self::lostZero($array['num'],'numPrecision')));
                $clockRuleTr .= <<<efo
<p class='m-b-30'>{$input}{$button}</p>
efo;
            }
        } else {
            $button = "<span class='op-but' onclick='addRow(this)'>+</span>";
            $input = hidden(array('name' => 'mxId[]', 'value' => self::getId())) . select(array('name' => 'problem[]', 'title' => '请选择', "class" => "b-b-input-30", 'option' => $defectOption)) . text(array('name' => 'num[]',"class"=>"text b-b-input-30", 'title' => '数量', 'value' => ''));
            $clockRuleTr .= <<<efo
<p class='m-b-30'>{$input}{$button}</p>
efo;
        }
        $waitReport = $machining_send_order['num']-$reportNum;
        $process_report['yield'] = $process_report['id']?$process_report['yield']:($waitReport<0?0:$waitReport);
        //生成页面
        $html = $this->commonHead('生产报工')."
		<div class='center'>
           <div class='onion'>
                <div class='back-but'><img onclick=\"window.location.href=root+'pad/index.html?cla=workReport&fun=home'\" src='".root."img/control/return.svg' alt=''></div>
                <div class='flex-div onion-text'>
                    <p>
                        <span>派工单：</span>
                        <span>{$machining_send_order['orderNo']}</span>
                    </p>
                </div>
            </div>
           <div class='center'>
                <form name='editForm'>
                    <div class='center-text'>
                        <ul>
                            <li>生产线：".$line['workshop'] . '-' . $line['name']."</li>
                            <li>工序：{$process['name']}</li>
                            <li>加工类型：{$machining_send_order['type']}</li>
                            <li>计价方式：{$routing_detail['valuationType']}</li>
                        </ul>
                        <ul>
                            <li>计划开始时间：{$machining_send_order['startDate']}</li>
                            <li>计划下线时间：{$machining_send_order['endDate']}</li>
                            <li>备注：{$machining_send_order['text']}</li>
                            <li></li>
                        </ul>
                        <ul>
                            <li>物料：{$name}</li>
                            <li>计划数量：".self::lostZero($machining_send_order['num'],'numPrecision')."</li>
                            <li>已报工：".self::lostZero($reportNum,'numPrecision')." {$machining_send_order['unit']}</li>
                            <li>待报工：".$waitReport." {$machining_send_order['unit']}</li>
                        </ul>
                    </div>
                    <div class='center-operation'>
                        <div class='operation-partition partition-left'>
                            <div class='f-l-35'>
                                <p class='m-t-b-30'><span class='head-span-new text-r'>班组：</span><span class='head-input-span'>".idSelect([
                'name'     => 'teamId',
                'id'       => 'teamId',
                'value'    => $teamId,
                'sqlForm'  => "team where coid = '".self::$coid."' and state = '启用' ",
                'class'    => 'b-b-select',
                'sqlId'    => 'id',
                'sqlField' => 'name',
                'null'     => true,
            ])."</span></p>
                                <p class='m-t-b-30'><span class=''>备注：</span><span class='head-input-span'>".text(array("name"=>"text","class"=>"b-b-input","value"=>$process_report['text']))."</span></p>
                                <p class='m-t-b-30'><span class=''>不良数量：</span><span class='head-input-span'>".text(array("name"=>"badNum","other"=>self::digitalFiltering('numPrecision'),"class"=>"text b-b-input","value"=>self::lostZero($process_report['badNum'],'numPrecision')))."</span></p>
                            </div>
                            <div class='f-l-65'>
                                <p class='m-t-b-30'><span class=''>班次：</span><span class='head-input-span'>".text(array("name"=>"teamNo","class"=>"b-b-input-40","laydate"=>[],"other"=>"readonly","value"=>$process_report['teamNo']?:$this->date)).select(array('name' => 'teamType', 'option' => $teamType,'class' => 'b-b-input-40', 'title' => '请选择', 'value' => $process_report['teamType'] ?: $teamType[0]))."</span></p>
                                <p class='m-t-b-30'><span class=''>开始结束时间：</span><span class='head-input-span'>".text(array("name"=>"startTime","class"=>"b-b-input-40","laydate"=>['type'=>'datetime'],"other"=>"readonly","value"=>self::null($process_report['startTime'], false))).text(array("name"=>"endTime","class"=>"b-b-input-40","laydate"=>['type'=>'datetime'],"other"=>"readonly","value"=>self::null($process_report['endTime'], false)))."</span></p>
                                <div class='m-t-b-30' style='display: flex'>
                                    <div class=''>缺陷类型：</div>
                                    <div class='head-input-span row-li'>
                                        " . $clockRuleTr . "
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class='operation-partition border-r calculator-back-gray'>
                            <p class='partition-title'>产量：<span>".text(array("name"=>"yield","other"=>self::digitalFiltering('numPrecision'),"class"=>"text width100","value"=>self::lostZero($process_report['yield'],'numPrecision')))."</span></p>
                            {$calculator}
                        </div>
                    </div>
                    ".hidden(array('name' => 'sendId', 'value' => $machining_send_order['id'])).
            hidden(array('name' => 'processId', 'value' => $process['id'])).
            hidden(array('name' => 'id', 'value' => $id)).
            "
                </form>
            </div>
		</div>
		<div class='footer-two'>
            <p>
                <button type='button' class='newButton-left' onClick=\"subForm('editForm',root+'pad/index.html?cla=workReport&fun=reportEdit')\">保存</button>
                <button type='button' class='newButton' onClick=\"subForm('editForm',root+'pad/index.html?cla=workReport&fun=reportEdit&sign=post')\">提交</button>
            </p>
		</div>".$this->commonNavigation('生产报工');
        $js   = "
        <script>
        //添加一行
         function addRow(){
             let processId = $(\"[name='processId']\").val();
             if (!processId){
                 msg('请先选择工序','error');
             }else{
                 $.post(root+'pad/index.html?cla=workReport&fun=addRow',{processId:processId},function (res){
                     $('.row-li').append(res.data);
                 },'json');
             }
         }
        $(function(){
            
        })
        </script>".$this->jsReport();
        return head("report") . $html . $js . warn() . "\n</body>\n</html>";
    }

    /**
     * 添加一行
     *
     * @return bool|string
     */
    public function addRow()
    {
        $process = query('process', "id = '" . $this->post('processId') . "'");
        $defectOption = $process['id'] ? explode('，', $process['defectType']) : [];
        $button = "<span class='op-but' onclick='decRow(this)'>-</span>";
        $input = hidden(array('name' => 'mxId[]', 'value' => self::getId())) . select(array('name' => 'problem[]', 'title' => '请选择', "class" => "b-b-input-30", 'option' => $defectOption)) . text(array('name' => 'num[]',"class"=>"b-b-input-30","type"=>"number", 'title' => '数量', 'value' => ''));
        $json['data'] = "<p class='m-b-30'>" . hidden(array('name' => 'mxId[]', 'value' => self::getId())) . $input. $button . "</p>";
        return json_encode($json, 320);
    }

    /*编辑*/
    public function reportEdit()
    {

        $id = $this->post('id') ?: self::getId();
        $state = $this->get('sign')=='post'?'待确认':'草稿';

        $problemArr = $this->post('problem') ?: [];
        $numArr = $this->post('num') ?: [];
        $mxIdArr = $this->post('mxId') ?: [];
        $teamStaffId = $this->post('teamStaffId');
        //赋值
        $field = array(
            "startTime" => $this->post('startTime'),
            "endTime" => $this->post('endTime'),
            "sendId" => $this->post('sendId'),//备注
            'teamNo' => $this->post('teamNo'),
            "teamType" => $this->post('teamType'),
            "teamId" => $this->post('teamId'),
            "yield" => $this->post('yield'),
            "badNum" => $this->post('badNum'),
            "text" => $this->post('text'),
            'state' => $state
        );
        $machiningSendOrder = query('machining_send_order', "id = '$field[sendId]'");
        $field['materialId'] = $machiningSendOrder['materialId'];
        $field['processId'] = $machiningSendOrder['processId'];
        $field['routingId'] = $machiningSendOrder['routingId'];
        $field['routingMxId'] = $machiningSendOrder['routingMxId'];
        $field['lineId'] = $machiningSendOrder['lineId'];
        $field['unit'] = $machiningSendOrder['unit'];
        $routing_detail = query('routing_detail', "id = '$field[routingMxId]'");
        $field['valuationType'] = $routing_detail['valuationType'];
        $annotation = [
            "sendId" => '生产派工单',
            'teamNo' => '班次',
            "teamType" => '班次',
            "teamId" => '班组',
            "yield" => '产量',
            "processId" => '工序',
            "materialId" => '物料ID',
            "routingId" => '工艺路线',
            "routingMxId" => '工艺路线明细',
            "lineId" => '生产线',
            "valuationType" => '计件方式',
            "unit" => '单位',
        ];
        $rules = [
            "sendId" => 'required',
            'teamNo' => 'required',
            "teamType" => 'required',
            "teamId" => 'required',
            "yield" => 'required|numeric',
            'processId' => 'required',
            "materialId" => 'required',
            "routingId" => 'required',
            'routingMxId' => 'required',
            "lineId" => 'required',
            "valuationType" => 'required',
            "unit" => 'required',
        ];

        // 校验是否符合规则
        $vt = new \verify();
        $result = $vt->setAliases($annotation)->validate($field, $rules)->isOk();
        if ($result === false) {
            $json['warn'] = $vt->getErrs()[0];  // 多个规则提示最前面一条
            goto resp;
        }
        $info = query('process_report', " id = '" . $id . "' ");
        //判断
        if (!$this->power('processReport', "edit")) {
            $json['warn'] = "权限不足";
        } elseif ($info['state'] == '已确认') {
            $json['warn'] = '此报工已确认，不能编辑';
        } elseif (!empty($field['startTime']) && !empty($field['endTime']) && strtotime($field['endTime']) < strtotime($field['startTime'])) {
            $json['warn'] = '结束时间不能小于开始时间';
        } else {
            $this->startTrans();
            if (empty($info['id'])) {
                $userNo = self::generateCode('processReport',[
                    'prefix' => 'BG' . date('Ymd'),
                    'table' => 'process_report',
                    'field' => 'orderNo',
                    'where' => " and coid = '".self::$coid."'",
                ],$field);
                $field = array_merge($field, array("id" => $id, 'coid' => self::$coid, 'orderNo' => $userNo, 'state' => '草稿', 'stid' => $this->control['stid']));
                $json['warn'] = insert(array("table" => 'process_report', "field" => $field));
            } else {
                $json['warn'] = update(array("table" => 'process_report', "field" => $field, "where" => "id = '$info[id]'"));
            }
            $newIdArr = [];
            if (is_array($mxIdArr)) {
                foreach ($mxIdArr as $k => $mxId) {
                    if (!empty($problemArr[$k])) {
                        $newIdArr[] = $mxId;
                        $mx = query('process_report_detail', "id = '$mxId'");
                        if (!empty($mx['id'])) {
                            $warn = static::update(array(
                                'table' => 'process_report_detail',
                                'field' => array(
                                    'problem' => $problemArr[$k],
                                    'num' => $numArr[$k],
                                ),
                                'where' => "id = '$mx[id]'",
                            ));
                        } else {
                            $warn = static::insert(array(
                                'table' => 'process_report_detail',
                                'field' => array(
                                    'id' => $mxId,
                                    'coid' => self::$coid,
                                    'orderId' => $id,
                                    'problem' => $problemArr[$k],
                                    'num' => $numArr[$k],
                                ),
                            ));
                        }
                        if (!in_array($warn, array("新增成功", "更新成功"))) {
                            $json['warn'] = $warn;
                            break;
                        }
                    }
                }
            }
            if ($field['valuationType'] == '个人计件') {
                delete(array('table' => 'process_report_staff', 'where' => "orderId = '$id'"));
                $warn = static::insert(array(
                    'table' => 'process_report_staff',
                    'field' => array(
                        'id' => suiji(),
                        'coid' => self::$coid,
                        'orderId' => $id,
                        'stid' => $teamStaffId,
                    ),
                ));
                if (!in_array($warn, array("新增成功", "更新成功"))) {
                    $json['warn'] = $warn;
                }
            }

            if (in_array($json['warn'], array("新增成功", "更新成功"))) {
                $this->commitTrans();
                delete(array('table' => 'process_report_detail', 'where' => " id not in ('" . implode("','", $newIdArr) . "') and orderId = '$id'"));
                if ($json['warn'] == '新增成功') {
                    auditingFollow(array(
                        "type" => "工序报工",
                        "typeId" => $id,
                        "text" => "【{$this->control['name']}】新建",
                        'job' => self::findStaffDepartment(self::$stid) . '-' . $this->controlJob['name'],
                        'staffName' => $this->control['name'],
                    ));
                }
                if($this->get('sign')=='post')auditingFollow(array(
                    "type" => "工序报工",
                    "typeId" => $id,
                    "text" => "【{$this->control['name']}】提交",
                    'job' => self::findStaffDepartment(self::$stid) . '-' . $this->controlJob['name'],
                    'staffName' => $this->control['name'],
                ));
                //添加日志
                $type = mb_substr($json['warn'], 0, 2, 'utf-8');
                $text = $this->control['name'] . $type . "了工序报工ID：" . $id;
                $this->logText(array("type" => 'processReport', "text" => $text));
                //返回
                $_SESSION['warn'] = $json['warn'];
                $json['warn'] = 2;
            } else {
                $this->rollback();
            }
        }
        $json['id'] = $id;
        if($this->get('sign')=='post') {
            $json['href'] = root . "pad/index.html?cla=workReport&fun=home";
        }else{
            $json['href'] = root . "pad/index.html?cla=workReport&fun=workReportDetail&id=".$id;
        }
        resp:
        return json_encode($json, 320);
    }

    /*******生产报工-存储筛选条件到SESSION*******/
    public function conditions(){
        $product_line = find(array("table" => "product_line", "field" => "concat(workshop,'-',name) as name,id", "where" => " coid = '".self::$coid."' and state = '启用' "));
        $line_arr = !empty($product_line['array'])?array_column($product_line['array'], 'name', 'id'):[];
        //筛选数据
        $data = array(
            array(
                "text"=>"开工日期",
                "name"=>"date",
                "type"=>"radio",
                "value"=>['今天','昨天','近三天','本周','本月'],
            ),
            array(
                "text"=>"状态",
                "name"=>"state",
                "type"=>"radio",
                "value"=>['待报工','部分报工','已报工'],
            ),
            array(
                "text"=>"加工类型",
                "name"=>"type",
                "type"=>"checkbox",
                "value"=>['生产加工', '生产返工'],
            ),
            array(
                "text"=>"生产线",
                "name"=>"product_line",
                "type"=>"checkbox",
                "value"=>$line_arr,
            ),
        );
        $type = self::type; //类型报工
        //组成新的数据存为session
        $arr = [];
        $text = [];
        $conditionArr = [];
        foreach ($data as $array){
            switch ($array['type'])
            {
                case "radio":
                    $choice = $this->post($array['name']) ?[$this->post($array['name'])]: [];
                    break;
                default:
                    $choice = $this->post($array['name']) ?: [];
            }
            $value = [];
            //如果用此数组中所有的值组成的数组完全等于此数组，则说明此数组为索引数组，反之为关联数组
            if (array_values($array['value']) === $array['value']) {
                foreach ((array)$array['value'] as $item) {
                    $checked = in_array($item, $choice);
                    if ($checked) {
                        $text[] = $item;
                        if (isset($conditionArr[$array['name']])) {
                            $conditionArr[$array['name']][] = $item;
                        } else {
                            $conditionArr[$array['name']] = [$item];
                        }
                    }
                    $value[] = [
                        'name' => $item,
                        'checked' => $checked,
                    ];
                }
            }else{
                foreach ((array)$array['value'] as $key => $item) {
                    $checked = in_array($key, $choice);
                    if ($checked) {
                        $text[] = $item;
                        if (isset($conditionArr[$array['name']])) {
                            $conditionArr[$array['name']][] = $key;
                        } else {
                            $conditionArr[$array['name']] = [$key];
                        }
                    }
                    $value[$key] = [
                        'name' => $item,
                        'checked' => $checked,
                    ];
                }
            }
            $array['value'] = $value;
            $arr[] = $array;
        }
        //重置则恢复默认
        if(empty($text)){
            $arr[0]['value'][0]['checked'] = true;
            $arr[1]['value'][0]['checked'] = true;
            $conditionArr['date'] = ['今天'];
            $conditionArr['state'] = ['待报工'];
            $text[] = '今天';
            $text[] = '待报工';
        }
        $_SESSION[$type]['search'] = $arr;
        $_SESSION[$type]['orderNo'] = $this->post('orderNo');
        $_SESSION[$type]['search_text'] = implode('，',$text);
        $_SESSION[$type]['condition_arr'] = $conditionArr;
        $json['warn'] = 2;
        return json_encode($json, 320);
    }

}

